/*
 * phc -- the open source PHP compiler
 * See doc/license/README.license for licensing information
 *
 * Generate C code
 *
 * We define a virtual class "Pattern" which corresponds to a particular kind
 * of statement that we can generate code for. We inherit from Pattern to 
 * define the various statements we can translate, create instances of each
 * of these classes, and then for every statement in the input, cycle through
 * all the patterns to find one that matches, and then call "generate" on that
 * pattern.
 */

// TODO Variable_variables cannot be used to access superglobals. See warning
// in http://php.net/manual/en/language.variables.superglobals.php
// TODO: that is not true - add a test case.

// TODO:
//		magic methods are:
//			__construct
//			__destruct
//			__get
//			__set
//			__unset
//			__isset
//			__call
//			__toString
//			__serialize
//			__unserialize
//
//	So that means casts are pure.

#include <fstream>
#include <boost/format.hpp>

#include "lib/List.h"
#include "lib/Set.h"
#include "lib/Map.h"
#include "lib/escape.h"
#include "lib/demangle.h"
#include "process_ir/General.h"
#include "process_ir/XML_unparser.h"
#include "codegen/Generate_C_annotations.h"
#include "process_mir/MIR_to_AST.h"
#include "pass_manager/Pass_manager.h"

#include "Generate_C.h"
#include "parsing/MICG_parser.h"
#include "embed/embed.h"

using namespace boost;
using namespace MIR;
using namespace std;

/**
   just pass through this to a macro MyStatic
*/
class Pattern_static : public Pattern
{
public:
	bool match(Statement* that)
	{
	  //Name_with_default* var

		variable_name = new Wildcard<Name_with_default>;
		return that->match(new Static_declaration(variable_name));
	}

	void generate_code(Generate_C* gen)
	{
	  String * pString= variable_name->value->value;

	  //MIR::VARIABLE_NAME
	  buf << "MyStatic(" << *pString << ");\n";
	}

protected:
	Wildcard<MIR:Name_with_default>* variable_name;
};

Pattern * createPattern_static()
{
  return new Pattern_static();
}


/**
<MIR:Static_declaration>
	<attrs>
		<attr key="phc.filename"><string>./Parser2.php</string></attr>
		<attr key="phc.line_number"><integer>547</integer></attr>
	</attrs>
	<MIR:Name_with_default>
		<attrs>
			<attr key="phc.filename"><string>./Parser2.php</string></attr>
			<attr key="phc.line_number"><integer>547</integer></attr>
		</attrs>
		<MIR:VARIABLE_NAME>
			<attrs>
				<attr key="phc.codegen.st_entry_not_required"><bool>true</bool></attr>
			</attrs>
			<value>privateRanges</value>
		</MIR:VARIABLE_NAME>
		<MIR:BOOL>
			<attrs>
				<attr key="phc.filename"><string>./Parser2.php</string></attr>
				<attr key="phc.line_number"><integer>547</integer></attr>
			</attrs>
			<value>False</value>
		</MIR:BOOL>
	</MIR:Name_with_default>
</MIR:Static_declaration>

*/
